<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>导航栏和内容框示例</title>
    <style>
        body {
            margin: 0;
            font-family: Arial, sans-serif;
        }

        /* 导航栏样式 */
        .navbar {
            display: flex;
            align-items: center;
            justify-content: space-between;
            background-color: #333;
            padding: 10px 20px;
            color: white;
        }
        .navbar .logo img {
            height: 40px;
        }
        .navbar .system-name {
            flex: 1;
            text-align: center;
            font-size: 24px;
            font-weight: bold;
        }
        .navbar .titles a {
            text-decoration: none;
            color: white;
            font-weight: bold;
        }
        .navbar .titles a:hover {
            text-decoration: underline;
        }

        /* 页面布局 */
        .main-container {
            display: flex;
            height: calc(100vh - 60px); /* 除去导航栏的高度 */
        }

        /* 左侧垂直菜单样式 */
        .sidebar {
            width: 200px;
            border-right: 1px solid #ccc;
            background-color: #f9f9f9;
            padding: 10px;
            box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
        }
        .menu-item {
            position: relative;
            cursor: pointer;
            padding: 10px;
            border-bottom: 1px solid #eee;
        }
        .menu-item:hover {
            background-color: #e0e0e0;
        }
        .menu-item:hover::after {
            content: attr(data-tooltip);
            position: absolute;
            left: 100%;
            top: 50%;
            transform: translateY(-50%);
            background-color: #333;
            color: white;
            padding: 5px 10px;
            border-radius: 4px;
            white-space: nowrap;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        }
        .submenu {
            display: none;
            background-color: #fff;
            padding-left: 20px;
            margin-top: 5px;
            border-left: 2px solid #ccc;
        }
        .submenu a {
            display: block;
            padding: 5px 0;
            color: #333;
            text-decoration: none;
        }
        .submenu a:hover {
            text-decoration: underline;
        }
        .menu-item.active .submenu {
            display: block !important;
        }

        /* 右侧内容框样式 */
        .content {
            flex: 1;
            padding: 20px;
            background-color: #fff;
            overflow-y: auto;
            box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.1);
        }
        .content h1 {
            margin-top: 0;
        }

        /* 表格样式 */
        .hr-archive-table {
            width: 100%;
            border-collapse: collapse;
        }
        .hr-archive-table th, .hr-archive-table td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        .hr-archive-table th {
            background-color: #f2f2f2;
            font-weight: bold;
        }
        .hr-archive-table tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        .hr-archive-table .action-buttons button {
            margin: 0 5px;
            padding: 5px 10px;
            cursor: pointer;
        }
    </style>
</head>
<body>
<!-- 顶部导航栏 -->
<div class="navbar">
    <div class="logo">
        <img src="/image/校徽.png" alt="图标">
    </div>
    <div class="system-name">人力资源管理系统</div>
    <div class="titles">
        <a href="../index.jsp">首页</a>
        <a href="#about">关于</a>
        <a href="#contact">联系我们</a>
    </div>
</div>

<!-- 页面主体布局 -->
<div class="main-container">
    <!-- 左侧垂直菜单 -->
    <div class="sidebar">
        <div class="menu-item" data-tooltip="人力资源管理模块">
            人力资源管理模块
            <div class="submenu">
                <a href="../humanAdd.jsp">添加档案</a>
                <a href="humanQuery.jsp">档案查询和管理</a>
            </div>
        </div>
        <div class="menu-item" data-tooltip="管理薪酬">
            薪酬管理模块
            <div class="submenu">
                <a href="salaryStandard.jsp">薪酬标准制定</a>
            </div>
        </div>
    </div>

    <!-- 右侧内容框 -->
    <div class="content">
        <h1>人力资源档案数据</h1>
        <table class="hr-archive-table">
            <thead>
            <tr>
                <th>姓名</th>
                <th>性别</th>
                <th>年龄</th>
                <th>电话</th>
                <th>所属部门</th>
                <th>薪酬标准</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody id="hr-archive-data">
            <!-- 数据将在这里动态插入 -->
            </tbody>
        </table>
    </div>
</div>

<script>
    $(document).ready(function() {
        // 获取人力资源数据并显示在表格中
        $.ajax({
            url: 'human', // 确保这个URL路径是正确的
            method: 'GET',
            success: function(response) {
                console.log('Response:', response); // 打印响应数据到控制台
                if (response.code === 1) {
                    var hrArchiveList = response.data;
                    var tableBody = $('#hr-archive-data');
                    tableBody.empty();

                    if (hrArchiveList && hrArchiveList.length > 0) {
                        hrArchiveList.forEach(function(hrArchive) {
                            var genderText = hrArchive.gender === 1 ? '男' : '女';
                            var row = `<tr>
                                <td>${hrArchive.name || ''}</td>
                                <td>${genderText}</td>
                                <td>${hrArchive.age || ''}</td>
                                <td>${hrArchive.phone || ''}</td>
                                <td>${hrArchive.department_name || ''}</td>
                                <td>${hrArchive.salary || ''}</td>
                                <td class="action-buttons">
                                    <button class="edit-btn" data-id="${hrArchive.id}">修改</button>
                                    <button class="delete-btn" data-id="${hrArchive.id}">删除</button>
                                </td>
                            </tr>`;
                            tableBody.append(row);
                        });
                    } else {
                        tableBody.append('<tr><td colspan="7">没有数据</td></tr>');
                    }
                } else {
                    alert('获取数据失败：' + response.msg);
                }
            },
            error: function(xhr, status, error) {
                console.error('请求失败：', xhr, status, error); // 打印错误信息到控制台
                alert('请求失败：' + error);
            }
        });

        // JavaScript 实现下拉菜单功能
        $('.menu-item').click(function() {
            // 切换当前菜单项的 active 类，控制子菜单展开与收起
            $(this).toggleClass('active');
        });
    });
</script>
</body>
</html>
